package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Subject;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 学科控制层
 * @author: 小雷
 * @createTime: 2023-11-14 00:24:20
 */
@Slf4j
@RestController
@RequestMapping("/subject")
@Api(value = "学科控制层", tags = "学科访问操作接口")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 条件查询所有学科
     *
     * @param subject 学科实体类，包含所有查询条件
     * @return
     */
    @GetMapping
    @ApiOperation(value = "分类筛选学科信息")
    public JsonRequest<List<Subject>> lookSubject(
            @ApiParam(value = "学科信息", required = true)
            Subject subject) {
        return subjectService.lookSubject(subject);
    }

    /**
     * 新增学科
     *
     * @param subject 学科实体类
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增学科信息")
    public JsonRequest<Integer> addSubject(
            @ApiParam(value = "学科信息", required = true)
            @RequestBody Subject subject) {
        return subjectService.addSubject(subject);
    }

    /**
     * 修改学科信息
     *
     * @param subject 需要修改的实体类
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改学科信息")
    public JsonRequest<Integer> updateSubject(
            @ApiParam(value = "修改的学科信息", required = true)
            @RequestBody Subject subject) {
        return subjectService.updateSubject(subject);
    }

    /**
     * 删除学科信息
     *
     * @param ids 需要删除的学科id
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除学科")
    public JsonRequest<Integer> deleteSubject(
            @ApiParam(value = "删除学科的id", required = true)
            @RequestBody List<String> ids) {
        return subjectService.deleteSubject(ids);
    }
}

